package aquarium.factory;

import java.awt.Point;

import aquarium.gui.Aquarium;
import aquarium.items.*;
import aquarium.items.Sex;
import aquarium.time.TManager;
import aquarium.util.RandomNumber;

public class FishFactory extends AquariumItemFactory<Fish> {

	private TManager _tmanager;


	public FishFactory(TManager tmanager) {
		this._tmanager = tmanager;
	}

	@Override
	public NormalFish newItems() {
		int size = RandomNumber.randomValue(NormalFish.getMinWidth(), NormalFish.getMaxWidth());
		Point position = RandomNumber.randomPoint(0, Aquarium.SIZE_AQUA_X-NormalFish.getMaxWidth(), 0, Aquarium.SIZE_AQUA_Y-NormalFish.getMaxWidth());
		Point target = RandomNumber.randomPoint(0, Aquarium.SIZE_AQUA_X-NormalFish.getMaxWidth(), 0, Aquarium.SIZE_AQUA_Y-NormalFish.getMaxWidth());
		Sex sex = random_sex();
		NormalFish f = new NormalFish(position, size, 100, -1, target, sex, false, _tmanager);
		return f;
	}

	public Fish newItems(FishType type) {
		Fish f = null;
		switch (type) {
		case Normal: {
			int size = RandomNumber.randomValue(NormalFish.getMinWidth(), NormalFish.getMaxWidth());
			Point position = RandomNumber.randomPoint(0, Aquarium.SIZE_AQUA_X-NormalFish.getMaxWidth(), 0, Aquarium.SIZE_AQUA_Y-NormalFish.getMaxWidth());
			Point target = RandomNumber.randomPoint(0, Aquarium.SIZE_AQUA_X-NormalFish.getMaxWidth(), 0, Aquarium.SIZE_AQUA_Y-NormalFish.getMaxWidth());
			Sex sex = random_sex();
			f = new NormalFish(position, size, 100, -1, target, sex, false, _tmanager);
			return f;
		}
		case OneSecond : {
			int size = RandomNumber.randomValue(OneSecondFish.getMinWidth(), OneSecondFish.getMaxWidth());
			Point position = RandomNumber.randomPoint(0, Aquarium.SIZE_AQUA_X-OneSecondFish.getMaxWidth(), 0, Aquarium.SIZE_AQUA_Y-OneSecondFish.getMaxWidth());
			Point target = RandomNumber.randomPoint(0, Aquarium.SIZE_AQUA_X-OneSecondFish.getMaxWidth(), 0, Aquarium.SIZE_AQUA_Y-OneSecondFish.getMaxWidth());
			Sex sex = random_sex();
			f = new OneSecondFish(position, size, 100, 1000, target, sex, false, _tmanager);
			return f;
		}
		case Piscivore : {
			int size = RandomNumber.randomValue(PiscivoreFish.getMinWidth(), PiscivoreFish.getMaxWidth());
			Point position = RandomNumber.randomPoint(0, Aquarium.SIZE_AQUA_X-PiscivoreFish.getMaxWidth(), 0, Aquarium.SIZE_AQUA_Y-PiscivoreFish.getMaxWidth());
			Point target = RandomNumber.randomPoint(0, Aquarium.SIZE_AQUA_X-PiscivoreFish.getMaxWidth(), 0, Aquarium.SIZE_AQUA_Y-PiscivoreFish.getMaxWidth());
			Sex sex = random_sex();
			f = new PiscivoreFish(position, size, 100, 500, target, sex, false, _tmanager);
			return f;
		}
		default: {
			int size = RandomNumber.randomValue(NormalFish.getMinWidth(), NormalFish.getMaxWidth());
			Point position = RandomNumber.randomPoint(0, Aquarium.SIZE_AQUA_X-NormalFish.getMaxWidth(), 0, Aquarium.SIZE_AQUA_Y-NormalFish.getMaxWidth());
			Point target = RandomNumber.randomPoint(0, Aquarium.SIZE_AQUA_X-NormalFish.getMaxWidth(), 0, Aquarium.SIZE_AQUA_Y-NormalFish.getMaxWidth());
			Sex sex = random_sex();
			f = new NormalFish(position, size, 100, -1, target, sex, false, _tmanager);
			return f;
		}
		}
	}

	private Sex random_sex(){
		int cmp = RandomNumber.randomValue(0, 1);
		if (cmp == 0)
			return Sex.Female;
		return Sex.Male;
	}
}
